#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :utils.py
# @Time      :2022/01/20 18:33:54
# @Author    :hengdin
import os
import json

# 获取当前项目路径
def get_project_path():
    project_path = os.path.dirname(os.path.dirname(__file__))
    return project_path

# 获取配置文件的路径
def get_config_path(dirname, filename):
    project_path = get_project_path()
    return os.path.join(project_path, dirname, filename)



# 获取配置信息
def get_config(dirname,filename):
    config_path = get_config_path(dirname,filename)
    return read_json_file(config_path)




# 获取国家json
def get_country_map():
    project_path = get_project_path()
    country_map_path = os.path.join(project_path, "config", "country_map.json")
    with open(country_map_path,'r',encoding="utf-8")as f:
        return json.load(f)

# 获取语种json
def get_language_map():
    project_path = get_project_path()
    language_path = os.path.join(project_path, "config", "language.json")
    with open(language_path,'r',encoding="utf-8")as f:
        return json.load(f)

# 获取领域分类json
def get_field_map():
    project_path = get_project_path()
    field_map_path = os.path.join(project_path, "config", "field_map.json")
    with open(field_map_path,'r',encoding="utf-8")as f:
        return json.load(f)




def read_json_file(json_file_path):
    with open(json_file_path,"r",encoding="utf-8")as f:
        return json.load(f)

if __name__ == "__main__":
    config = get_config()
    # print(config)
    country_map = get_field_map()
    print(country_map)
